package com.jqb.struts2lab01.interceptor;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class UserInterceptor implements Interceptor {

	private static final long serialVersionUID = 1L;
	
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		Object user = ActionContext.getContext().getSession().get("user");
		// 如果user不为null,表示用户已经登陆，允许执行action中的方法
		if (user != null){
			return invocation.invoke();
		}
		ActionContext.getContext().put("msg", "请登录先");
		return "success";
	}
	
	@Override
	public void destroy() {	}

	@Override
	public void init() { }


}
